package handlers

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"priv-repo-sys/model"
)

func Add(c *gin.Context) {
	title := c.PostForm("title")
	name := c.PostForm("name")
	if title == "" || name == "" {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400,
			"msg": "字段不为空"})
		return
	}
	data := model.Acc{
		Title: title,
		Name:  name,
	}
	err := model.DB.Create(&data).Debug().Error
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400,
			"msg": "添加失败"})
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": 200,
		"msg": "添加成功"})
	return
}
func List(c *gin.Context) {
	var art []model.Acc
	model.DB.Debug().Find(&art)
	c.JSON(http.StatusOK, gin.H{"code": 200,
		"data": art,
		"msg":  "展示成功"})
}
